<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 100px;
            height: 100px;
        }
        .containter{
            height: 200px;
        }
        .containter1{
            height: 200px;
        }
        .containter2{
            height: 200px;
        }
        .containter .box{
            background: pink;
            display: block;
        }
        .containter .box1{
            background: skyblue;
            display: none;
        }
        .containter .box2{
            background: yellowgreen;
            display: none;
        }

        .containter1 .box{
            background: pink;
            display: block;
        }
        .containter1 .box1{
            background: skyblue;
            display: none;
        }
        .containter1 .box2{
            background: yellowgreen;
            display: none;
        }

        .containter2 .box{
            background: pink;
            display: block;
        }
        .containter2 .box1{
            background: skyblue;
            display: none;
        }
        .containter2 .box2{
            background: yellowgreen;
            display: none;
        }
    </style>
</head>
<body>
    <div class="containter">
        <button>按钮一</button>
        <button>按钮二</button>
        <button>按钮三</button>
        <div class="box"></div>
        <div class="box1"></div>
        <div class="box2"></div>
    </div>
    <div class="containter1">
        <button>按钮一</button>
        <button>按钮二</button>
        <button>按钮三</button>
        <div class="box"></div>
        <div class="box1"></div>
        <div class="box2"></div>
    </div>
    <div class="containter2">
        <button>按钮一</button>
        <button>按钮二</button>
        <button>按钮三</button>
        <div class="box"></div>
        <div class="box1"></div>
        <div class="box2"></div>
    </div>
    <script>
        let divs = document.querySelectorAll('.containter div')
        let btns = document.querySelectorAll('.containter button');
        Tab(divs,btns)

        let divs1 = document.querySelectorAll('.containter1 div')
        let btns1 = document.querySelectorAll('.containter1 button');
        Tab(divs1,btns1)

        let divs2 = document.querySelectorAll('.containter2 div')
        let btns2 = document.querySelectorAll('.containter2 button');
        Tab(divs2,btns2)



        function Tab(divs,btns){
        btns.forEach(function(item,key){
            item.onclick = function(){
                divs.forEach(function(div,k){
                    if(key === k){
                    // 点击按钮的索引,把和按钮索引一样的div显示出来
                    div.style.display = 'block';
                    }else{
                    // 把和点击按钮不同的div隐藏起来
                    div.style.display = 'none';
                    }
                })
            }
        })
    }

    </script>
</body>
</html>